﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VgoCardChange.Models.Objects;
using VgoCardChange.Models;

namespace VgoCardChange.Controllers
{
    public class ServerController : Controller
    {
        //
        // GET: /Server/

        public ActionResult Index()
        {
            return View();
        }
        public ActionResult GetServers()
        {
            List<Server> listsv = new List<Server>();
            ServerModels SvMd = new ServerModels();
           listsv= SvMd.GetServer();
           ViewData["listserver"] = listsv;
           return View();

        }
        public ActionResult CreateServer()
        {
            GameModels GameMd = new GameModels();
            ViewData["listgame"] = new SelectList(GameMd.GetGames(), "GameID", "GameName");
            return View();
        }
        [HttpPost]
        public ActionResult CreateServer(string ServerName, string Description, int listgame)
        {
            ServerModels SvdMd = new ServerModels();
            Server sv= new Server();
            sv.ServerName = ServerName;
            sv.Desciption = Description;
            sv.GameID = listgame;
            SvdMd.CreateServer(sv);
            return RedirectToAction("GetServers");
        }
        public ActionResult EditServer(int ServerID)
        {
            GameModels GameMd = new GameModels();
            ViewData["listgame"] = new SelectList(GameMd.GetGames(), "GameID", "GameName", ServerID);
            ServerModels SvMd = new ServerModels();
            List<Server> listserverdid = new List<Server>();
            listserverdid = SvMd.GetServerID(ServerID);
            ViewData["listserverid"] = listserverdid;
            return View();
        }
        [HttpPost]
        public ActionResult EditServer(int ServerID, string ServerName, string Description, int listgame)
        {
            ServerModels ServerMd = new ServerModels();
            Server sv = new Server();
            sv.ServerID = ServerID;
            sv.ServerName = ServerName;
            sv.Desciption = Description;
            sv.GameID = listgame;
            ServerMd.EditServer(sv);
            return RedirectToAction("GetServers");

        }
        public ActionResult DeleteServer(int ServerID)
        {
            ServerModels SvMd = new ServerModels();
            List<Server> listserverdid = new List<Server>();
            listserverdid = SvMd.GetServerID(ServerID);
            ViewData["listserverid"] = listserverdid;
            return View();
        }
        [HttpPost]
        public ActionResult DeleteServer(int ServerID, FormCollection coll)
        {
            ServerModels SvMd = new ServerModels();
            SvMd.DeleteServer(ServerID);
            return RedirectToAction("GetServers");
        }


    }
}
